<?php
namespace xcom\model;
use x\Xbase;

class Log extends Xbase {
	//记录日志
	public function record($user_id = 0, $msg = '', $tab = 'user') {
		if ($user_id) {
			$rs = $this->db->find($tab, $user_id, 'username');
			$username = $rs ? $rs['username'] : '';
			$msg = $username . "于" . date("Y-m-d H:i") . "-" . $msg;
		} else {
			$msg = "于" . date("Y-m-d H:i") . "-" . $msg;
		}
		$data = [
			'user_id' => $user_id,
			'tab' => $tab,
			'msg' => $msg,
			'm' => $this->m,
			'c' => $this->c,
			'a' => $this->a,
			'ip' => ip(),
			'create_time' => time(),
		];
		return $this->db->insert('log', $data);
	}
}
